<template>
  <div>
    <WorkOrderSubmitDialog :visible="workOrderDialogVisible" @changeDialogState="changeDialogState" @dialogSubmit="dialogSubmit" :stats-options="statsOptions" :service-list="serviceList"/>
    <div class="work-panel">
      <div class="Initiate-container">
        <el-button class="Initiate">
          <span @click="workOrderDialogVisible = true">+ {{$t('发起新工单')}}</span>
        </el-button>
        <div @click="getInfoWorkList" class="refresh"></div>
      </div>
      <div class="work-list">
        <el-card :key="index" v-for="(workInfo, index) in workInfoList" class="box-card" >
          <el-form ref="form" :model="form" label-width="80px">
            <el-form-item :label="$t('工单类型')">
              <span>{{workInfo.worderType}}</span>
            </el-form-item>
            <el-form-item :label="$t('工单内容')">
              <span>{{workInfo.worderData}}</span>
            </el-form-item>
            <el-form-item :label="$t('工单状态')">
              <el-tag v-if="workInfo.worderStatus === '等待处理'">{{workInfo.worderStatus}}</el-tag>
              <el-tag v-if="workInfo.worderStatus === '处理成功'" type="success">{{workInfo.worderStatus}}</el-tag>
              <el-tag v-if="workInfo.worderStatus === '处理失败'" type="danger">{{workInfo.worderStatus}}</el-tag>
            </el-form-item>
            <el-form-item :label="$t('处理结果')">
              <span>{{workInfo.worderResult}}</span>
            </el-form-item>
            <el-form-item :label="$t('创建时间')">
              <span>{{workInfo.createTime}}</span>
            </el-form-item>
            <el-form-item :label="$t('更新时间')">
              <span>{{workInfo.updateTime}}</span>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
      <div class="order">
        <div class="order-container">
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import WorkOrderSubmitDialog from "@/views/workorder/WorkOrderSubmitDialog";
import apiService from "@/api/apiService";
export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: "WorkOrderList",
  components: {WorkOrderSubmitDialog},
  data() {
    return {
      workOrderDialogVisible: false,
      orderWorkList: [],
      statsOptions:[],
      serviceList:[],
      workInfoList:[],
      form: {
        wOrderType: '哈哈哈',
        wOrderData: '哈哈哈',
        wOrderStatus: '哈哈哈',
        wOrderResult: '哈哈哈',
        createTime: '2024-10-14',
        updateTime: '2024-10-14',
      }
    }
  },
  watch: {

  },
  mounted() {
    this.$nextTick(function () {
      this.getInfoWorkList()
    })
  },
  methods: {
    getInfoWorkList(){
      apiService.get("/info-work").then(res => {
        this.workInfoList = res.data
      })
    },
    changeDialogState(state){
      this.workOrderDialogVisible = state
    },
    dialogSubmit(req) {
      apiService.post('/add-work',req).then(() => {
          this.$message.success('提交成功')
          this.getInfoWorkList()
      }).catch((e)=>{
        this.$message.error('提交失败',e)
      })
    },
  }
};
</script>

<style>
  #app {
    text-align: left;
  }
.work-panel {
  box-shadow: 0 0 0 .2rem #00000005;
  border-radius: 10px;
  border: solid white 1px;
  background: rgb(255, 255, 255);
  margin: auto;
  width: 95%;
}

.inline-input{
  width: 100%;
}



.order{
  text-align: left;
}

.order-info{
  text-align: left;
}

.order-container{
  display: flex;
  flex-wrap: nowrap;
  gap: 20px;
}

.Initiate{
  background: #3560ee;
  color: white;
  font-size: 15px;
  font-weight: bolder;
    margin-left: .5rem;
    margin-top: .5rem;
}

.Initiate-container{
  background: rgb(255, 255, 255);
  margin: auto;
  width: 100%;
  text-align: left;
}

.refresh{
  border-radius: 50%;
  background-image: url('@/assets/refresh.svg');
  background-size: contain;
  float: right;
  margin-top: .5rem;
  margin-right: .5rem;
  width: 20px;
  height: 20px;
}

.refresh:hover{
  background-color: #cccccc;
  cursor: pointer;
}


.workOrder-dialog{
  min-width: 90vw !important;
}
</style>
